package edu.calpoly.android.echoes;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class RenameView extends Activity {
	
	LinearLayout m_layout = null;
	EditText m_name = null;	
	Button m_set = null;
	
	Intent myIntent = null;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		myIntent = getIntent();
		String name = myIntent.getStringExtra("oldName");
		
		m_layout = new LinearLayout(this);
		setContentView(m_layout);
		
		m_name = new EditText(this);
		m_name.setText(name);
		m_set = new Button(this);
		m_set.setText("Set Name");
		
		m_layout.addView(m_name);
		m_layout.addView(m_set);
		
		m_set.setOnClickListener(new View.OnClickListener() {
			

			public void onClick(View v) {
				setName();
				
			}
		});
		
		
	}
	
	private void setName() {
		if(m_name != null) {
			String s = m_name.getText().toString();
			myIntent.putExtra("newName", s);
			setResult(RESULT_OK, myIntent);
			finish();
		}
		setResult(RESULT_CANCELED, myIntent);
		finish();
	}

}
